

#include "GPS.h"

//void VenusGPS::init(){
//
//		payload = 0;
//        m_restart_t restart;
//        uint16_t len = sizeof(m_restart_t);
//        //memset(&restart, 0, len);
//		restart.start_mode = 0x03;//0x03 for cold restart
//		restart.altitude = 50;
//		restart.latitude = 4227;  //these values are fairly accurate
//		restart.longitude = -7234;
//		restart.utc_year = 2012;	
//        payload = (uint8_t*) &restart;
//        //send(M_RESTART, payload, len);
//
//}
//
//
//uint8_t VenusGPS::calcCRC(uint8_t type, uint8_t pldCRC[], uint8_t start, uint16_t runlen){
// uint8_t crc = 0, n=0;
//
// crc ^= type;
//
// for(n=start; n<runlen; n++){
//         crc ^=pldCRC[n];
// }
//
// return crc;
//}
//
//
//void VenusGPS::send(uint8_t type, uint8_t pldSending[], uint16_t len){
//        int n;
//        uint8_t crc;
//
//        crc = calcCRC(type, pldSending, 0, len);
//
//        Serial.write(START1);
//        Serial.write(START2);
//        Serial.write((uint8_t*)&len, 2);
//        Serial.write(type);
//
//        Serial.write(payload, len);
//
//        Serial.write(crc);
//        Serial.write(END1);
//        Serial.write(END2);
//}



Coordinate GPS::process(volatile uint8_t GPS_packet[]){
	
	Coordinate returnCoord;
	uint8_t latBuff[4];
	uint8_t lonBuff[4];
	
	
	numSats = GPS_packet[5];

	int i;
	for(i=0; i<4; i++){ //I put my MSB leading bytes down, flip it and reverse it
		latBuff[i] = GPS_packet[15-i];
		lonBuff[i] = GPS_packet[19-i];
	}

	//is it worth it?
	returnCoord.lat = *(long*)((uint8_t*)(&latBuff[12]));
	returnCoord.lon = *(long*)((uint8_t*)(&lonBuff[16]));
	returnCoord.timeStamp = millis();

	return returnCoord;
}

GPS gps;
